const log4js = require('log4js');
var os = require("os")
console.log(os.platform());
var config = require('../config')
if (os.platform() == 'darwin') {
    config = require('../config_osx');
}

const format = require('string-format')
format.extend(String.prototype, {
    escape: s => s.replace(/[&<>"'`]/g, c => '&#' + c.charCodeAt(0) + ';'),
    upper: s => s.toUpperCase(),
})

log4js.configure({
    appenders: {
        stdout: { type: 'stdout' },
        logfile: { type: 'file', filename: 'cards.log' }
    },
    categories: { default: { appenders: ['logfile', 'stdout'], level: 'debug' } }
});

const logger = log4js.getLogger('card-server');

global.logger = logger
global.request_handler = {}
global.notify_handler = {}
global.protocol = require('../common/protocol');
global.mysqldb = require('./tools/db');
global.mysqldb.init(config.mysql());
global.appdef = require('./defines');
global.usermgr = require('./usermgr');
global.roommgr = require('./roommgr');


require('./handlers/request_handler');
require('./websocket_service').start(3333);